
<?php

require_once  __DIR__ . '/includes/authenticate.php';
include_once './db_bb_connect.php';


if (isset($_POST['team']) && isset($_POST['season'])) {

    $team = $_POST['team'];
    $season = $_POST['season'];

    $sql4 = "SELECT text
    FROM opponents
    WHERE season = '$season' AND teamname = '$team'";

    $result4=$db->query($sql4);
    $row4=$result4->fetch_assoc();
    $text=$row4['text'];  
?>

<div id="subcontent">
<h4>Edit Opponent Info of <?= $team; ?> of season <?= $season; ?></h4>

<form>
	
<br>
<input type="hidden" name="season" value="<?= $season; ?>">
<input type="hidden" name="team" value="<?= $team; ?>">
<textarea class="form-control" name="text" placeholder="Opponent information" rows="10" ><?= $text; ?></textarea>

<br>

<button class="form-control btn btn-success" id="submit" type="submit">Update</button>


</form>
<br>
</div>


<?php } ?>

<script type="text/javascript">
	
$("#submit").on("click", function(e) {
    postData = $(this.form).serialize();
    $.ajax({
        type: "POST",
        url: "./opponents_add_handler.php",
        data: postData,
        success: function(data) { 
            $("#subcontent").html(data); 
        },
        error: function (xhr, status, error) {
        	$("#subcontent").html(xhr.responseText); 
        }
      }); 
    e.preventDefault();
});  

</script>